package com.guaika.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guaika.reggie.common.ResultMessage;
import com.guaika.reggie.common.StringChars;
import com.guaika.reggie.entity.Orders;
import com.guaika.reggie.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author GuaiKa
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @PostMapping("/submit")
    public ResultMessage<String> save(@RequestBody Orders orders){
        ordersService.submit(orders);
        return ResultMessage.success(StringChars.PAY_SUCCESS.getStr());
    }

    @GetMapping("/page")
    public ResultMessage<Page> page(int page, int pageSize, String number, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date beginTime, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime){
        return ordersService.ordersPage(page, pageSize, number,beginTime,endTime);
    }

    @PutMapping
    public ResultMessage<String> updateStatusById(@RequestBody Orders orders){
        ordersService.updateById(orders);
        return ResultMessage.success(StringChars.PLAY_SUCCESS.getStr());
    }
}
